import Vue from 'vue'
import VueRouter from 'vue-router'
import {Message} from "element-ui"

Vue.use(VueRouter)

const originalPlush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPlush.call(this, location).catch(err => err)
}


const routes = [
    {
        path: '/',
        name: 'manager',
        redirect: '/home',
        component: () => import('../views/Manager.vue'),
        children: [
            {path: 'home', name: 'home', meta: {name: '系统首页'} ,component: () => import('../views/manger/Home.vue')},
            {path: 'user', name: 'user', meta: {name: '用户管理'} ,component: () => import('../views/manger/User.vue')},
            {path: 'info', name: 'info', meta: {name: '信息修改'} ,component: () => import('../views/manger/Information.vue')},
            {path: 'criterion', name: 'criterion', meta: {name: '查看指标'} ,component: () => import('../views/manger/Criterion.vue')},
            {path: 'criterionUpdate', name: 'criterionUpdate', meta: {name: '编辑指标'} ,component: () => import('../views/manger/CriterionUpdate.vue')},
            {path: 'experts', name: 'experts', meta: {name: '评估组设置'} ,component: () => import('../views/manger/Experts.vue')},
            {path: 'expertGroup', name: 'expertGroup', meta: {name: '总览'} ,component: () => import('../views/manger/ExpertsGroup.vue')},
            {path: 'status', name: 'status', meta: {name: '状态'} ,component: () => import('../views/evaluation/Status.vue')},
            {path: 'setGroup', name: 'setGroup', meta: {name: '分配考评组'} ,component: () => import('../views/evaluation/SetGroup.vue')},
            {path: 'gInput', name: 'gInput', meta: {name: '信息填报'} ,component: () => import('../views/evaluation/GschoolInput.vue')},
            {path: 'assess', name: 'assess', meta: {name: '评估'} ,component: () => import('../views/evaluation/Assess.vue')},
            {path: 'getScore', name: 'getScore', meta: {name: '查看成绩'} ,component: () => import('../views/evaluation/GetScore.vue')},
            {path: 'score', name: 'score', meta: {name: '结果数据'} ,component: () => import('../views/evaluation/Score.vue')},
        ]
    },
    {
        path: '/login',
        name: 'login',
        meta: {name: '登录'} ,
        component: () => import('../views/Login.vue')
    },
    {
        path: '*',
        name: '404',
        meta: {name: '404'},
        component: ()=> import('../views/404.vue')
    }

]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, form, next) => {

    // let adminPaths = ['/user', '/criterion', 'criterionUpdate']
    // let user = JSON.parse(localStorage.getItem("user"))

    // if (user.role !== "" && adminPaths.includes(to.path)) {
    //     Message.error("权限不足")
    //     next("/home")
    // } else {
    //     next()
    // }
    next()
})

export default router
